<template>
  <div class="app-container">
    <el-form :model="queryParams" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公司" prop="noticeTitle" label-width="100px">
        <!--        <el-input v-model="queryParams.reason" placeholder="请输入名称" clearable @keyup.enter="handleQuery"/>-->
        <el-select v-model="queryParams.corpName" placeholder="请选择类别"  @change="handleQuery" clearable>
          <el-option v-for="(item, index) in typeOptions" :key="index" :label="item.unitname"
                     :value="item.unitname"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="Switch" @click="makeVoucher()">
          同步档案
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="gridData" cell-class-name="table_cell">
      <el-table-column prop="subjcode" label="科目编码" width="80" algin="center"/>
      <el-table-column prop="subjname" label="科目名称" width="85" show-overflow-tooltip algin="center"/>
      <el-table-column prop="dispname" label="显示名称" width="130" algin="center"/>
      <el-table-column prop="subjtypename" label="科目类型" algin="center"/>
      <el-table-column prop="cashbankflagName" label="现金分类" algin="center"/>
      <el-table-column prop="remcode" label="助记码" width="70" algin="center" />
      <el-table-column prop="balanorientName" label="科目方向" width="80" algin="center" />
      <el-table-column prop="bdname" label="辅助核算" width="80" algin="center" />
      <el-table-column prop="departmentAuxiliary" label="部门辅助" width="80" algin="center" />
      <el-table-column prop="projectAuxiliary" label="项目辅助" width="80" algin="center" />
      <el-table-column prop="specialFund" label="专项资金" width="80" algin="center" />
      <el-table-column prop="merchantsFile" label="客商档案" width="80" algin="center" />
      <el-table-column prop="bankAccount" label="银行账户" width="80" algin="center" />
      <el-table-column prop="contractFiles" label="合同档案" width="80" algin="center" />
      <el-table-column prop="taxiContractor" label="出租车承包人" algin="center" />
      <el-table-column prop="crop" label="公司" width="200" algin="center" />
      <el-table-column prop="yesOrNo" label="是否同步" width="80" algin="center" />
    </el-table>
    <el-pagination :total="total" v-model:current-page="listQuery.pageIndex" v-model:page-size="listQuery.pageSize"
                   @current-change="getList"/>

  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "ImportLog",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      selectionList: [],
      gridData: [],
      listQuery: {
        pageIndex: 1,
        pageSize: 10,
      },
      queryParams: {
        corpName: null,
      },
      total: 0,
      typeOptions: [],
      // 表单参数
      form: {},
      rules: {
        cdigest: [
          {
            pattern: /^(0|[1-9][0-9]*)$/,
            message: "请输入集团内8位编码",
            trigger: "blur"
          },
          {
            min: 8,
            max: 8,
            message: '请输入集团内8位编码',
            trigger: 'blur'
          }
        ],
      },
    }
  },
  watch: {
  },
  created() {
    this.getChargeType();
  },
  methods: {
    getChargeType(){
      request.get('/bdCorp/getList').then(res => {
        this.typeOptions = res.data;
      });
    },
    getList(){
      this.loading = true;
      request.get("/bdAccsubj/getList?pageIndex="+this.listQuery.pageIndex+"&pageSize="+this.listQuery.pageSize+"&corpName="+this.queryParams.corpName).then(res => {
        this.loading = false;
        this.total = res.data.total
        this.gridData = res.data.records;
        console.log(res)
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.listQuery.pageIndex = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.listQuery.pageIndex = 1;
      this.queryParams.reason = null;
      this.queryParams.chargeType = null;
      this.handleQuery();
    },
    makeVoucher(){
      let data = {
        ...this.listQuery,
        ...this.queryParams
      }
      request.post('/formmain0105/saveList105',data).then(res => {
        if(res){
this.$confirm('同步成功', '提示', {
            confirmButtonText: '确定',
            showCancelButton: false, //是否显示取消按钮
            type: 'success'
          }).then(() => {
            this.getList();
          });
        }else {
          this.$confirm('同步失败，请联系管理员', '提示', {
            confirmButtonText: '确定',
            showCancelButton: false, //是否显示取消按钮
            type: 'warning'
          }).then(() => {
            this.getList();
          });
        }
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      if (this.selectionList == null) {
        this.selectionList = selection;
      } else {
        this.selectionList = selection + this.selectionList
      }
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
      selection = this.selectionList;
    },
  }
}
</script>

<style scoped>

.mb8 {
  margin-bottom: 20px;
}

.app-container {
  margin: 0;
  height: 96%;
  padding: 30px 10px 10px;
  background-color: #FFFFFF;
}

.table_cell .cell {
  margin-top: 2%;
  white-space: pre-line !important;
}

</style>